﻿using System;
using System.Data;
using System.Collections.Generic;
using mydddd.BLL.other;
using Maticsoft.Common;
using mydddd.Model;
namespace mydddd.BLL
{
	/// <summary>
	/// sysModule
	/// </summary>
	public partial class SysModule
	{
	    /// <summary>
	    /// 更新绝对路径
	    /// </summary>
	    /// <param name="id"></param>
	    /// <returns></returns>
	    public bool UpdateModulePath(int id)
	    {
	        dal.UpdateParentNoEnd(id);
	        return dal.UpdateModulePath(id);
	    }

        /// <summary>
        /// 得到一个对象实体(父级的绝对路径)
        /// </summary>
	    public mydddd.Model.SysModule GetModulePathModel(int id)
        {
            return dal.GetModulePathModel(id);
        }

        /// <summary>
        /// 判断当前页面是否有权限
        /// </summary>
        /// <param name="sysRolepopedom_id">页面权限角色id</param>
        /// <param name="url">页面组件地址/标识</param>
        /// <returns></returns>
        public static bool IsRole(int sysRolepopedom_id, string url)
        {
            //从缓存中读取页面组件的数据,并判断权限
            //从缓存中读取数据
            DataSet dsTemp =
                CacheHelper.Get(sysRolepopedom.CacheName() + sysRolepopedom_id) as DataSet;

            //没有缓存从数据库中读取
            if (dsTemp == null)
            {
                DAL.SysModule dal1 = new DAL.SysModule();
                dsTemp = dal1.GetListBySysRolepopedomId(sysRolepopedom_id);
                //添加到缓存中
                CacheHelper.Insert(sysRolepopedom.CacheName() + sysRolepopedom_id, dsTemp);

                bool tempbool = dal1.IsRole(sysRolepopedom_id, url);
                dal1 = null;//销毁
                return tempbool;
            }
            else
            {
                object obj = dsTemp.Tables[0].Compute("count(id)", string.Format(" moduleUrl='{0}'", url));

                if (obj == null)
                {
                    return false;
                }
                else
                {
                    return Convert.ToInt32(obj) > 0;
                }
            }


        }
	}
}

